/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/24/12
 * Time: 7:26 PM
 */
Ext.define('CT.controller.Permisos', {
    extend: 'Ext.app.Controller',
    views:[
        'permiso.View',
        'permiso.Window'
    ],
    stores:[
        'Permisos'
    ],
    models:[
        'Permiso'
    ],

    win:false,
    init:function(){
        this.control({
            'viewpermisos':{
                itemclick:this.onClickItem
            }

        });
    },
    lanzarVentana:function(rol_k){
        if(!this.win){
            this.init();
        }
        this.rol_k=rol_k;
        this.win=Ext.widget('winpermisos',{iconCls:'permisos',rol_k:this.rol_k,modal:true});
        this.win.show();
    },
    onClickItem:function(view, record){
        var store = this.getPermisosStore();

        Ext.Ajax.request({
            url: 'index.php/permisos/edit',
            params: {
                permiso_k:record.data.permiso_k,
                modulo_k:record.data.modulo_k,
                accion_k:record.data.accion_k,
                rol_k: this.rol_k,
                permiso: record.data.permiso?0:1
            },
            success: function(response){
                store.load();
                Notification.ok('Permiso Modificado', ' ');
            }
        });


    }
});